package miao.demo.config;

import com.alibaba.druid.pool.DruidDataSource;
import miao.demo.dao.BookDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;
import java.util.Date;

public class JdbcConfig {

    //简单类型注入
    @Value("com.mysql.jdbc.Driver")
    private String driverClassName;

    @Value("jdbc:mysql//localhost:3306/spring_db")
    private String url;

    @Value("root")
    private String userName;

    @Value("root")
    private String passWord;
    @Bean

    //引用类型依赖注入 形参 配置扫描器
    public DataSource dataSource(BookDao bookDao){
        System.out.println(bookDao);
        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName(driverClassName);
        ds.setUrl(url);
        ds.setUsername(userName);
        ds.setPassword(passWord);
        return ds;
    }
}
